<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/12/05
 * Time: 14:09
 */

namespace HiCommon\Model;

class MaintainShopGoods extends Base
{

    protected $table = 'maintain_shop_goods';

    protected $guarded = [];

    //public $timestamps = false;

    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];

    public function goods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id')
            ->select('id', 'name');
    }

    public function product()
    {
        return $this->hasOne(GoodsProduct::class, 'id', 'product_id')
            ->with(['specs'])
            ->select('id', 'goods_specs_id', 'pic', 'price', 'stock');
    }

    /**
     * 获取图片可用链接
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getImgUrlAttribute($value)
    {
        $arr_data = [
            'src' => $value,
            'full_src' => oss_full_url($value),
        ];
        return $arr_data;
    }

    /**
     * 扩展信息
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function getExtendAttribute()
    {
        $s_created_at = $this->created_at;
        $arr_data = [
            'created_at' => ymd_friendly_date($s_created_at),
        ];

        return $arr_data;
    }


}